<template>
	<view class="container-white">
		<view class="head">
			<view>考试名称：{{ info.examName || '' }}</view>
			<view>交卷时间：{{ info.submitPaperTime || '' }}</view>
			<view>考试状态：{{ info.isPass > 0 ? '及格' : '未及格' }}</view>
		</view>
		<view
			v-if="Object.keys(info).length"
			style="text-align: center;margin-top: 10upx;margin-bottom: 40upx;display: flex;flex-direction: column;justify-content: center;align-items: center;"
		>
			<view class="score-circle">
				<view style="color: #999999;margin-top: 46upx;">分数</view>
				<view>
					<text style="color: #333333;font-size: 72upx;">{{ info.sumScore }}</text>
					<text style="color: #666666;margin-left: 20upx;">分</text>
				</view>
			</view>
			<view style="font-size:28upx;color:#999999;">答对：{{ info.quesRight }}题</view>
		</view>
		<view>
			<view style="display: flex;flex-wrap: wrap;padding: 0 20upx;">
				<view class="options" v-for="(item, index) in scantron" :key="index">
					<view class="stide" :class="item.answ ? (item.answ == item.rightAnsw ? 'correct' : 'mistake') : ''" @tap="wrongTopic(item, index)">{{ index + 1 }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { post_md5, request_integral } from '../../common/request';
export default {
	data() {
		return {
			info: {
				examType: 1
			},
			scantron: []
		};
	},
	onLoad(options) {
		this.goExamInfo(options.id);
	},

	onBackPress() {
		uni.redirectTo({
			url: '/pages/exam/exam-list?examType=' + this.info.examType
		});
		return true
	},
	onNavigationBarButtonTap() {
		uni.redirectTo({
			url: '/pages/exam/exam-list?examType=' + this.info.examType
		});
	},
	methods: {
		goExamInfo(id) {
			const params = {
				userId: uni.getStorageSync('userId'),
				examId: id
			};
			post_md5('/exam-app/exam/result', params).then(res => {
				this.info = res.data;
				this.scantron = res.data.listResult;
				if (parseInt(this.info.examType) == 1) {
					if (this.info.isRepairExam) {
						request_integral(`make_${this.info.isPass > 0 ? 'ok' : 'err'}`, id);
					} else {
						request_integral(`exam_${this.info.isPass > 0 ? 'ok' : 'err'}`, id);
					}
				} else {
					request_integral(`simulation_${this.info.isPass > 0 ? 'ok' : 'err'}`, id);
				}
			});
		},
		// 查看错题
		wrongTopic(item, index) {
			uni.navigateTo({
				url: `answer?examId=${item.examId}&userId=${item.userId}&quesId=${item.quesId}&total=${this.scantron.length}&index=${index}`
			});
		}
	}
};
</script>

<style>
.head {
	font-size: 28upx;
	font-family: HiraginoSansGB-W3;
	font-weight: normal;
	color: #666666;
	border-top: 1px solid #ededed;
	padding: 20upx;
	line-height: 40upx;
}

.score-circle {
	width: 230upx;
	height: 230upx;
	border: 1px solid #999999;
	border-radius: 50%;
	font-size: 28upx;
	margin-bottom: 20upx;
	/* text-align: center; */
}

.options {
	width: 118upx;
	display: flex;
	justify-content: center;
}

.stide {
	margin: 0;
}

.correct {
	background: #3ed325;
	color: #ffffff;
	border: 1px #3ed325 solid;
}

.mistake {
	background: #ec6663;
	color: #ffffff;
	border: 1px #ec6663 solid;
}
</style>
